<template>
  <i class="action" :title="text" @click="handleClick">
    <svg
      aria-hidden="true"
      :class="svgClass"
      :style="{ color: props.color, size: props.size }"
    >
      <use :xlink:href="iconName" />
    </svg>
  </i>
</template>

<script setup>
  import { computed } from 'vue';

  const props = defineProps({
    text: {
      type: String,
      default: '',
    },
    name: {
      type: String,
      required: true,
    },
    color: {
      type: String,
      default: '#333',
    },
    size: {
      type: String,
      default: '1em',
    },
  });

  const iconName = computed(() => `#icon-${props.name}`);
  const svgClass = computed(() => `svg-icon icon-${props.name}`);

  const emits = defineEmits(['command']);

  const handleClick = () => {
    emits('command');
  };
</script>

<style lang="scss" scoped>
  .svg-icon {
    width: 1em;
    height: 1em;
    fill: currentColor;
    vertical-align: middle;
  }
</style>
